// UserContext.js
import React, { createContext, useContext, useState } from 'react';

const UserContext = createContext();

const UserProvider = ({ children }) => {
    const [userInfo, setUserInfo] = useState({
        avatar: "1.jpg",
        nickname: "烦",
        douyinId: "抖音号: 1231231",
        age: "",
        introduction: ""
    });

    const updateUserInfo = (newInfo) => {
        setUserInfo(prevInfo => ({
            ...prevInfo,
            ...newInfo
        }));
    };

    return (
        <UserContext.Provider value={{ userInfo, updateUserInfo }}>
            {children}
        </UserContext.Provider>
    );
};

const useUserContext = () => {
    return useContext(UserContext);
};

export { UserProvider, useUserContext };